/*
 *  Copyright (C) 2017 OrionStar Technology Project
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

import { action, observable } from 'mobx';
import {
    RelocationType,
    ResetEstimateParam,
    Pose,
    LocationEstimateUtil
} from 'orionos-eve-core';

export class ResetEstimateModel {
    /**
     * 重定位参数
     */
    private readonly mResetEstimateParam: ResetEstimateParam;

    //是否正在执行
    @observable private mIsRunning: boolean = false;

    //执行结果
    @observable private mResultText: string = '';

    /**
     * 构造函数
     */
    public constructor() {
        this.mResetEstimateParam = new ResetEstimateParam(
            5, 500, RelocationType.TYPE_VISION);
    }

    /**
     * 视觉重定位
     */
    @action
    public visionResetEstimate(): void {
        this.mResetEstimateParam.param_reset_estimate_type = RelocationType.TYPE_VISION;
        this.mIsRunning = true;
    }

    /**
     * 充电桩重定位
     */
    @action
    public chargingPoleResetEstimate(): void {
        this.mResetEstimateParam.param_reset_estimate_type = RelocationType.TYPE_FIXED;
        new LocationEstimateUtil().getLocation('充电桩').then((params: any) => {
            this.mResetEstimateParam.param_reset_estimate_pose = new Pose(params.px, params.py, params.theta);
            this.mIsRunning = true;
        });
    }

    /**
     * 执行结束
     */
    @action
    public finishRunning(): void {
        this.mIsRunning = false;
    }

    /**
     * 获取参数
     */
    public getParam(): ResetEstimateParam {
        return this.mResetEstimateParam;
    }

    /**
     * 是否执行
     */
    public isRunning(): boolean {
        return this.mIsRunning;
    }

    /**
     * 设置执行结果
     * @param text-结果
     */
    @action
    public appendResultText(text: string): void {
        this.mResultText += '\n' + text;
    }

    /**
     * 获取执行结果
     */
    public getResultText(): string {
        return this.mResultText;
    }
}